
export default class MovieFrame {

    constructor() {
        this._actions = [];
    }

    get numActions() {
        return this._actions ? this._actions.length : 0;
    }

    addAction(action) {
        if (action == null) {
            throw new Error("action cannot be null");
        }
        if (this._actions.indexOf(action) == -1) {
            this._actions[this._actions.length] = action;
        }
    }

    removeAction(action) {
        if (this._actions) {
            let index = this._actions.indexOf(action);
            if (index >= 0) {
                this._actions.splice(index, 1);
            }
        }
    }

    removeActions() {
        if (this._actions) {
            this._actions.length = 0;
        }
    }

    executeActions(target, frameID) {
        if (this._actions) {
            for (let i = 0, len = this._actions.length; i < len; ++i) {
                let action = this._actions[i];
                let numArgs = action.length;
                if (numArgs == 0) {
                    action();
                } else if (numArgs == 1) {
                    action(target);
                } else if (numArgs == 2) {
                    action(target, frameID);
                } else {
                    throw new Error("Frame actions support zero, one or two parameters: " +
                        "movie:MovieClip, frameID:int");
                }
            }
        }
    }
}